home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / polyptr_3d.cp < prev    next >
Encoding:
Text File  |  1995-11-17  |  5.1 KB  |  92 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    polyptr.cp
  3. //    Date:                    9/24/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the class methods for a reference
  7. //                                counted polygon pointer.
  8. //
  9. //------------------------------------------------------------------------------
  10.  
  11. #include "polyptr_3d.h"
  12.  
  13. //------------------------------------------------------------------------------
  14. //    constructor
  15. //------------------------------------------------------------------------------
  16. polyptr::polyptr (void)                                                                                                                    //    normal constructor
  17. {                                                                                                                                                                //    begin
  18.     ptr = 0;                                                                                                                                            //    empty polygon
  19. }                                                                                                                                                                //    end
  20.  
  21. //------------------------------------------------------------------------------
  22. //    constructor
  23. //------------------------------------------------------------------------------
  24. polyptr::polyptr (point_3d *buffer, int count, ...)                                                            //    normal constructor
  25. {                                                                                                                                                                //    begin
  26.     va_list    pts;                                                                                                                                    //    standard arg parameter list
  27.     va_start (pts, count);                                                                                                                //    set up the variable parameters
  28.     ptr = new rcpolygon (buffer, count, pts);                                                                            //    allocate the new polygon
  29.     va_end (pts);                                                                                                                                    //    finish up the paramter list
  30.     ptr->ref_count++;                                                                                                                            //    increment the reference count
  31. }                                                                                                                                                                //    end
  32.  
  33. //------------------------------------------------------------------------------
  34. //    constructor
  35. //------------------------------------------------------------------------------
  36. polyptr::polyptr (rcpolygon *poly)                                                                                            //    normal constructor
  37. {                                                                                                                                                                //    begin
  38.     ptr = poly;                                                                                                                                        //    copy the polygon pointer
  39.     if (ptr)                                                                                                                                            //    if it's valid
  40.         ptr->ref_count++;                                                                                                                        //    increment the reference count
  41. }                                                                                                                                                                //    end
  42.  
  43. //------------------------------------------------------------------------------
  44. //    constructor
  45. //------------------------------------------------------------------------------
  46. polyptr::polyptr (polyptr &poly)                                                                                                //    copy constructor
  47. {                                                                                                                                                                //    begin
  48.     ptr = poly.ptr;                                                                                                                                //    copy the pointer from the polyptr
  49.     if (ptr)                                                                                                                                            //    if it's valid
  50.         ptr->ref_count++;                                                                                                                        //    increment the reference count
  51. }                                                                                                                                                                //    end
  52.  
  53. //------------------------------------------------------------------------------
  54. //    destructor
  55. //------------------------------------------------------------------------------
  56. polyptr::~polyptr (void)                                                                                                                //    destructor
  57. {                                                                                                                                                                //    begin
  58.     if (ptr)                                                                                                                                            //    if the representation is valid
  59.         if (--(ptr->ref_count) == 0)                                                                                                //    if the decremented reference is zero
  60.             delete ptr;                                                                                                                                //    delete the representation
  61. }                                                                                                                                                                //    end
  62.  
  63. //------------------------------------------------------------------------------
  64. //    assignment
  65. //------------------------------------------------------------------------------
  66. polyptr        &polyptr::operator = (rcpolygon *poly)                                                                //    assignment operator
  67. {                                                                                                                                                                //    begin
  68.     if (poly)                                                                                                                                            //    if this is a valid rep
  69.         poly->ref_count++;                                                                                                                    //    increment its reference count
  70.     if (ptr)                                                                                                                                            //    if the current representation is valid
  71.         if (--(ptr->ref_count) == 0)                                                                                                //    if the decremented reference is zero
  72.             delete ptr;                                                                                                                                //    delete the representation
  73.     ptr = poly;                                                                                                                                        //    copy the new representation pointer
  74.     return *this;                                                                                                                                    //    return the reference to this
  75. }                                                                                                                                                                //    end
  76.  
  77. //------------------------------------------------------------------------------
  78. //    assignment
  79. //------------------------------------------------------------------------------
  80. polyptr        &polyptr::operator = (const polyptr &poly)                                                        //    assignment operator
  81. {                                                                                                                                                                //    begin
  82.     if (poly.ptr)                                                                                                                                    //    if this is a valid rep
  83.         poly.ptr->ref_count++;                                                                                                            //    increment its reference count
  84.     if (ptr)                                                                                                                                            //    if the current representation is valid
  85.         if (--ptr->ref_count == 0)                                                                                                    //    if the decremented reference is zero
  86.             delete ptr;                                                                                                                                //    delete the representation
  87.     ptr = poly.ptr;                                                                                                                                //    copy the new representation pointer
  88.     return *this;                                                                                                                                    //    return the reference to this
  89. }                                                                                                                                                                //    end
  90.  
  91. //------------------------------------------------------------------------------
  92.